package admin

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"strconv"
	"time"
)

type BaseController struct{}

// 成功和失败的控制器，接收三个参数，*gin.Context引擎、message 返回的消息、redirectUrl要跳转的url
func (con BaseController) Success(c *gin.Context, message string, redirectUrl string) {
	c.HTML(http.StatusOK, "admin/public/success.html", gin.H{
		"message":     message,
		"redirectUrl": redirectUrl,
	})

}

func (con BaseController) Error(c *gin.Context, message string, redirectUrl string) {
	c.HTML(http.StatusOK, "admin/public/error.html", gin.H{
		"message":     message,
		"redirectUrl": redirectUrl,
	})

}

// 获取时间戳
func (con BaseController) GetTime() int {
	timeNow := time.Now()
	unixNow := timeNow.Unix()
	return int(unixNow)
}

// 把string转换为int
func (con BaseController) StringInt(str string) (int, error) {
	n, err := strconv.Atoi(str)
	return n, err
}

// 把int转换为string
func (con BaseController) IntString(n int) string {
	str := strconv.Itoa(n)
	return str
}
